
#import "FAMCameLoadingView.h"
@interface FAMCameLoadingView()<PAGViewListener>
@property (weak, nonatomic) IBOutlet UIView *FAMPAGBackView;
@property (nonatomic, strong)PAGView *FAMPagView;
@property (weak, nonatomic) IBOutlet UILabel *FAMLoadingLabel;
@property (nonatomic, assign)float FAMSchedulelTimer;
@end
@implementation FAMCameLoadingView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"FAMCameLoadingView" owner:self options:nil];
        self = array.firstObject;
        NSString *path = [[NSBundle mainBundle]pathForResource:@"loading" ofType:@"pag"];
        self.FAMPagView = [[PAGView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [self.FAMPAGBackView addSubview:self.FAMPagView];
        PAGFile *pagFile = [PAGFile Load:path];
        [self.FAMPagView setComposition:pagFile];
        [self.FAMPagView setRepeatCount:1];
        [self.FAMPagView addListener:self];
        [self.FAMPagView play];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}

- (void)onAnimationEnd:(PAGView *)pagView{
    self.FAMLoadingLabel.text = @"100%";
}
- (void)onAnimationUpdate:(PAGView *)pagView{
    self.FAMSchedulelTimer += 0.4;
    WeakSelf(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        weakSelf.FAMLoadingLabel.text = [NSString stringWithFormat:@"%0.f%%",weakSelf.FAMSchedulelTimer];
    });
}
- (void)FAM_removeSelf{
    [self removeFromSuperview];
}

@end
